//任务接收方列表
var taskReceiverList = Ext.create('Ext.grid.Panel', {
    store: taskReceiverListStore,
//    overflowX: 'hidden', //设置横向滚动条不显示
//    overflowY: 'auto', //设置纵向滚动条超出高度显示
    //height: document.documentElement.clientHeight-170,
    columns: [
        {
            text: "任务名字", flex: 1, dataIndex: 'name',
            filter: {//用于形成搜索框
                type: 'string',
                emptyText: '输入要搜索的任务名字',
                serializer: function (filter) {
                    return filter.value;
                }
            }
        },
        {text: "状态", dataIndex: 'statusName'},
        {text: "优先级", dataIndex: 'priorityName'}
    ],
    columnLines: true,
    selModel: taskReceiverListCheckBox,
    bbar: taskReceiverListPagingBar,
    plugins: {
        rowexpander: {
            rowBodyTpl: new Ext.XTemplate(
                '<b>下达者:</b> {responsible}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
                '<b>任务类型:</b>',
                ' {typeName}<br><br>',
                '<b>任务创建日期:</b> {createDate:date("Y-m-d H:i:s")}',//2019-08-14 22:19:22
                '<p><b>任务描述:</b> {description}</p>',
                '<b>附件：</b>',
                '<tpl if="isAttachment != 0">',// 判断是否有附件
                '<tpl for="attached">',// 循环输出附件
                '&nbsp;&nbsp;<a href="javascript:void(0);" onclick="downloadAtta(\'{uuid}\',\'{attachedName}\',\'{fileType}\')">{attachedName}</a>',
                '</tpl>',
                '<tpl else>',
                '<b>无',
                '</tpl>'
            )
        },
        gridfilters: true,//启用filters
    },
    dockedItems: [
        {
            xtype: 'toolbar',
            items: [{
                text: '新建任务',
                itemId: 'addTaskButton',
                tooltip: '新建任务',
                icon: 'static/images/icons/fam/add.gif',
                listeners: {
                    click: function (button, e, eOpts) {
                        suitTaskFormForCreate();
                    }
                }
            }, '-', {
                xtype: 'combo',
                emptyText: '任务状态',
                editable: false,// 防止用户直接在下拉框里输入
                store: statusStoreforReceiver,
                width: 90,
                queryMode: 'local',
                displayField: 'statusName',
                valueField: 'statusNum',
                listeners: {
                    change: function (combo, newValue, oldValue, eOpts) {
                        filterReceiverTaskListByStatus(newValue);
                    }
                }
            }, '-', {
                itemId: 'receiverCompleteButton',
                text: '报告完成',
                tooltip: '报告完成',
                icon: 'static/images/icons/fam/accept.gif',
                disabled: true,
                listeners: {
                    click: function (button, e, eOpts) {
                        var item = taskReceiverList.getSelectionModel().getSelected();// 得到被选择的行的数组.
                        var flag = 1;
                        //循环判断选中项是否有不可操作项
                        for (i = 0; i < item.length; i++) {
                            if (item.items[i].data.statusName == '已完成' || item.items[i].data.statusName == '已取消') {
                                Ext.Msg.alert('警告', '选择项中包含不可操作项！');
                                flag = 0;
                                return;
                            }
                        }
                        if (flag != 0) {
                            Ext.Msg.show({
                                title: '提示',
                                message: '你确认完成这些任务了吗?',
                                buttons: Ext.Msg.YESNO,
                                icon: Ext.Msg.QUESTION,
                                fn: function (btn) {
                                    if (btn === 'yes') {
                                        var array = new Array();
                                        for (i = 0; i < item.length; i++) {
                                            array.push(item.items[i].data.id);
                                        }
                                        Ext.Ajax.request({
                                            url: zuulUrl + '/' + taskServiceName + '/status/receiver/'+currentUserId,
                                            method: 'put',
                                            defaultXdrContentType: 'application/json',
                                            jsonData: JSON.stringify(array),
                                            success: function (response, opts) {
                                                Ext.Msg.alert('成功', '任务完成成功');
                                                var count = 0;
                                                for (i = 0; i < item.length; i++) {
                                                    if (item.items[i].data.statusName == '未读')
                                                        count++;
                                                    item.items[i].set('statusName', '已完成');// 先手动修改本地store中的数据
                                                }
                                                taskTabPanel.down('#receiveTab').noReadCount = taskTabPanel.down('#receiveTab').noReadCount - count;
                                                taskNoReadSettle(taskTabPanel.down('#receiveTab').noReadCount);
                                            },
                                            failure: function () {
                                                Ext.Msg.alert("错误", "该功能暂时不可用！");
                                            }
                                        });
                                    }
                                }
                            });
                        }
                    }
                }
            }]
        }
    ],
    header: false,// 取消标题头的显示
    iconCls: 'icon-grid',
    margin: '0 0 20 0',
    sortableColumns: false,// 取消默认排序
    border: false
});

//添加展开监听事件
taskReceiverList.getView().on('expandBody', function (rowNode, record, expandRow, eOpts) {
    getTaskDetialForReceiver(record);
});
